package server;

import java.io.IOException;
import java.io.InputStream;

/**
 *
 */
public class Request {

  private String method;
  private String url;
  private InputStream inputStream;
  private String contextPath;

  public Request() {

  }

  public Request(InputStream inputStream) throws IOException {
    this.inputStream = inputStream;
    int count = 0;
    while (count == 0) {
      count = inputStream.available();
    }

    byte[] bytes = new byte[count];
    inputStream.read(bytes);
    String inputStr = new String(bytes);
    // 获取第一行请求头信息
    String firstLine = inputStr.split("\\n")[0]; // GET / HTTP/1.1
    String[] strings = firstLine.split(" ");
    this.contextPath = firstLine.split(" ")[1].split("/")[1];
    this.method = strings[0];
    this.url = strings[1];

    System.out.println("method:" + method);
    System.out.println("url:" + url);
  }

  public String getContextPath() {
    return contextPath;
  }

  public void setContextPath(String contextPath) {
    this.contextPath = contextPath;
  }

  public String getMethod() {
    return method;
  }

  public void setMethod(String method) {
    this.method = method;
  }

  public String getUrl() {
    return url;
  }

  public void setUrl(String url) {
    this.url = url;
  }

  public InputStream getInputStream() {
    return inputStream;
  }

  public void setInputStream(InputStream inputStream) {
    this.inputStream = inputStream;
  }
}
